home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_gwu / imain.c < prev    next >
C/C++ Source or Header  |  1996-01-30  |  6KB  |  246 lines

  1. /*
  2.  * Copyright (C) 1985-1992  New York University
  3.  * 
  4.  * This file is part of the Ada/Ed-C system.  See the Ada/Ed README file for
  5.  * warranty (none) and distribution info and also the GNU General Public
  6.  * License for more details.
  7.  
  8.  */
  9.  
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <ctype.h>
  13. #include <string.h>
  14. #include "config.h"
  15. #include "ivars.h"
  16. #include "slot.h"
  17. #include "ifile.h"
  18. #include "intap.h"
  19. #include "loadp.h"
  20. #include "miscp.h"
  21. #include "libfp.h"
  22.  
  23. #ifdef MONITOR
  24. #include "monitor.h"
  25. #include "mon_ext.h"
  26. #endif
  27.  
  28. #ifdef DEBUG
  29. int heap_store_offset = 0;
  30. #endif
  31.  
  32.  
  33. static void fold_lower(char *);
  34. static void fold_upper(char *);
  35.  
  36. /* global variable needed for imain.c, derived from generator */
  37. FILE *efopen();
  38.  
  39. main(int argc, char **argv)                                            /*;main*/
  40. {
  41.     int         c, i, n, status;
  42.     int         errflg = 0, nobuffer = 0;
  43.     char        *FILENAME;
  44.     IFILE       *ifile;
  45.     extern int  optind;
  46.     extern char *optarg;
  47.         int         lib_opt = FALSE;
  48.     char        *library_name, *fname;
  49.     char    *t_name;
  50.     Axq        axq;
  51.     char    *main_unit = (char *)0;
  52.     char     *tname;
  53.  
  54.     rr_flag = FALSE;
  55.     max_mem = MAX_MEM;
  56. #ifdef IBM_PC
  57.     new_task_size = 2048;
  58.     main_task_size = 4096;
  59. #else
  60.     main_task_size = 10000;
  61.     new_task_size = 10000;
  62. #endif
  63. #ifdef IBM_PC
  64.     while((c = getopt(argc,argv,"BbH:h:L:l:M:m:p:P:s:S:t:T:w:R:r:"))!=EOF){
  65. #else
  66.     while((c = getopt(argc,argv,"bh:l:m:p:s:t:w:r:"))!=EOF){
  67. #endif
  68.         /*    user:
  69.          *      h       heap size in kilobytes
  70.          *    l    library name
  71.          *    m    main unit name
  72.          *    p    main program task stack size
  73.          *    r    nb max consecutive stmts for the same task 
  74.                  *              (round-robin)
  75.          *    s    task stack size
  76.          *    t    tracing, followed by list of options:
  77.          *                a    Ada lines
  78.          *                c    calls 
  79.          *                e    exceptions
  80.          *                r    rendezvous
  81.          *                s    context-switches
  82.          *                t    tasks
  83.          *    debug (only):
  84.          *                d    debug
  85.          *          i     instruction
  86.          *    b    do not buffer standard output
  87.          *    w    off    trace stores at specified offset in heap
  88.          */
  89. #ifdef IBM_PC
  90.                 if (isupper(c)) c = tolower(c);
  91. #endif
  92.         switch(c) {
  93. #ifdef DEBUG
  94.         case 'b':    /* do not buffer standard output (for debugging) */
  95.             nobuffer++;
  96.             break;
  97.         case 'w':    /* storage write trace */
  98.             heap_store_offset = atoi(optarg);
  99.             break;
  100. #endif
  101.         case 'h': /* heap size in kilo bytes */
  102. #ifndef IBM_PC
  103.             max_mem = 1000*atoi(optarg);
  104. #else
  105.             {
  106.                 int optval; /* avoid too large value */
  107.                 optval = atoi(optarg);
  108.                 if (optval > 0 && optval < MAX_MEM/1000) 
  109.                     max_mem = 1000*optval;
  110.             }
  111. #endif
  112.             break;
  113.         case 'l': /* specify library name */
  114.                         lib_opt = TRUE;
  115.             library_name = strjoin(optarg,"");
  116.             break;
  117.         case 'm': /* specify main unit name */
  118.             main_unit = strjoin(optarg,"");
  119.             fold_upper(main_unit);
  120.             break;
  121.         case 'p': /* main task stack size */
  122.             i = atoi(optarg);
  123.             if (i > 0 && i < 31)     /* small value gives kilowords */
  124.                 main_task_size = i * 1024;
  125.             else if (i > 31)
  126.                 main_task_size = i;
  127.             break;
  128.         case 's': /* task stack size */
  129.             i = atoi(optarg);
  130.             if (i > 0 && i < 31)    /* small value gives kilowords */
  131.                 new_task_size = i * 1024;
  132.             else if (i > 31)
  133.                 new_task_size = i;
  134.             break;
  135.         case 'r': /* nb max consecutive stmts (round-robin) */
  136.             i = atoi(optarg);
  137.             if (i > 0) {
  138.                 rr_nb_max_stmts = i;
  139.                 rr_flag = TRUE;
  140.             }
  141.             else
  142.                             errflg++;
  143.             break;
  144.         case 't': /* interpreter trace arguments */
  145.             n = strlen(optarg);
  146.             for (i = 0; i < n; i++) {
  147. #ifdef IBM_PC
  148.                 if (isupper(optarg[i]))
  149.                                    optarg[i] = tolower(optarg[i]);
  150. #endif
  151.                 switch(optarg[i]) {
  152.                 case 'c': /* calls */
  153.                     call_trace++;
  154.                     break;
  155.                 case 'e': /* exceptions */
  156.                     exception_trace++;
  157.                     break;
  158.                 case 'a': /* Ada lines */
  159.                     line_trace++;
  160.                     break;
  161.                 case 'r': /* rendezvous */
  162.                     rendezvous_trace++;
  163.                     break;
  164.                 case 't': /* tasks */
  165.                     tasking_trace++;
  166.                     break;
  167.                 case 's': /* context-switches */
  168.                     context_sw_trace++;
  169.                     break;
  170. #ifdef DEBUG
  171.                 case 'd': /* debug */
  172.                     debug_trace++;
  173.                     break;
  174.                 case 'i': /* instructions */
  175.                     instruction_trace++;
  176.                     break;
  177. #endif
  178.                 default:
  179.                     errflg++;
  180.                     break;
  181.                 }
  182.             }
  183.             break;
  184.         case '?':
  185.             errflg++;
  186.         }
  187.     }
  188. #ifdef DEBUG
  189.     if (debug_trace)
  190.         printf("program, new task stack sizes %d %d\n",
  191.           main_task_size, new_task_size);
  192. #endif
  193.         fname = (char *)0;
  194.     if (optind < argc) fname = argv[optind];
  195.         if (!lib_opt && fname == (char *)0) { 
  196.         fname = getenv("ADALIB");
  197.     }
  198.     if ((!lib_opt && fname == (char *)0) || errflg) {
  199.         fprintf(stderr,
  200.           "Usage: adaexec -m main_unit -h size -r nb_stmts -t[acerst] [-l library]\n");
  201.         exit(RC_ABORT);
  202.     }
  203.         if (!lib_opt) {
  204.            library_name = emalloc(strlen(fname) + 1);
  205.            strcpy(library_name, fname);
  206.         }
  207. #ifdef DEBUG
  208.     if (nobuffer)
  209.         setbuf(stdout,(char *) 0);/* do not buffer output(for debug) */
  210. #endif
  211.     FILENAME = library_name;
  212.     t_name = libset(library_name);
  213.  
  214.     /* AXQFILE is opened by load_axq or library read (TBSL);*/
  215.     axq = (Axq) emalloc((unsigned) sizeof(Axq_s));
  216.     load_slots(FILENAME, &ifile, axq);
  217. #if GWUMON
  218.     {
  219.         int i;
  220.         for (i = 1; i < code_slots_dim; i++) 
  221.         CWK_BLKS[i].TN = code_slots[i];
  222.     }
  223. #endif
  224.     /* second arg to load_lib and load_axq is non-null if file open */
  225.     load_lib(FILENAME, ifile, axq, main_unit, argv);
  226.  
  227. #ifdef GWUMON
  228.     GWU_GET_MON();
  229. #endif
  230.     status = int_main();
  231. #ifdef GWUMON
  232.     CWK_CLEANUP_MON(0);
  233. #endif
  234. }
  235.  
  236. static void fold_upper(char *s)                    /*;fold_upper*/
  237. {
  238.     char c;
  239.  
  240.     while (*s) {
  241.         c = *s;
  242.         if (islower(c)) *s = toupper(c);
  243.         s++;
  244.     }
  245. }
  246.